/**
 * @brief    Tabular functions for generating dynamic loads.
 *
 * @version  0.1
 * @author   wuxingchuang
 * @date     2024.11.23
 *          _
 *      ___| |__   ___ _ __   __ _  ___  _ __   __ _
 *     / __| '_ \ / _ \ '_ \ / _` |/ _ \| '_ \ / _` |
 *     \__ \ | | |  __/ | | | (_| | (_) | | | | (_| |
 *     |___/_| |_|\___|_| |_|\__, |\___/|_| |_|\__, |
 *                           |___/             |___/
 * @copyright (c) 2024 by 神工仿真, All Rights Reserved.
 */
#pragma once
#include <memory>
#include "DataStructure/Common/Real.h"
#include "DataStructure/Input/Table/TABLEDObject.h"

SG_DATASTRUCTURE_FEM_NAMESPACE_OPEN

struct DECLSPEC TABLED1Data : public TABLEDObject
{
    /**
     * @brief    插值函数，支持线性和对数插值，以及边界外推
     * 
     * @param    t 输入感兴趣的自变量值，返回插值后的值
     * @return   插值结果
     * @author   wjw
     * @date     2025.03.05
     */
    SG::Algebra::Real_t Interpolate (SG::Algebra::Real_t t) const override;
    
    /**
     * @brief    检查是否为对数轴（LOG模式）
     */
    bool IsXAxisLog() const { return m_CODEX != 0; }
    bool IsYAxisLog() const { return m_CODEY != 0; }
    
    static SG::Algebra::Real_t InterpolateLinearLinear (SG::Algebra::Real_t xi, SG::Algebra::Real_t xj, SG::Algebra::Real_t yi, SG::Algebra::Real_t yj, SG::Algebra::Real_t t);
    static SG::Algebra::Real_t InterpolateLogLinear (SG::Algebra::Real_t xi, SG::Algebra::Real_t xj, SG::Algebra::Real_t yi, SG::Algebra::Real_t yj, SG::Algebra::Real_t t);
    static SG::Algebra::Real_t InterpolateLinearLog (SG::Algebra::Real_t xi, SG::Algebra::Real_t xj, SG::Algebra::Real_t yi, SG::Algebra::Real_t yj, SG::Algebra::Real_t t);
    static SG::Algebra::Real_t InterpolateLogLog (SG::Algebra::Real_t xi, SG::Algebra::Real_t xj, SG::Algebra::Real_t yi, SG::Algebra::Real_t yj, SG::Algebra::Real_t t);
    
    struct XYData
    {
        SG::DataStructure::Common::Real m_X = 0.0;  ///<
        SG::DataStructure::Common::Real m_Y = 0.0;  ///<
    };

    SG::DataStructure::Common::I64 m_CODEX    = 0;  ///< X轴插值类型：0=LINEAR, 非0=LOG
    SG::DataStructure::Common::I64 m_CODEY    = 0;  ///< Y轴插值类型：0=LINEAR, 非0=LOG
    SG::DataStructure::Common::Id  m_domainId = 0;  ///<

    std::vector<XYData> m_XYList;
};

using TABLED1DataP = std::shared_ptr<TABLED1Data>;

///@{ @brief operator override
DECLSPEC bool operator== (const TABLED1Data::XYData& val1, const TABLED1Data::XYData& val2);

DECLSPEC bool operator== (const TABLED1Data& val1, const TABLED1Data& val2);
///}@
SG_DATASTRUCTURE_FEM_NAMESPACE_CLOSE